package com.niuxiaofa.newlaw.adapter;

import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.niuxiaofa.newlaw.Bean.TimeBean;
import com.niuxiaofa.newlaw.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class ConsultationTimeAdapter extends RecyclerView.Adapter<ConsultationTimeAdapter.ViewHolder> {
    public List<TimeBean> listEntities;
    Onclick onclick;

    int current = 0;

    public ConsultationTimeAdapter(List<TimeBean> newsList, Onclick onclick) {
        this.onclick = onclick;
        this.listEntities = newsList;
    }

    
    @Override
    public ViewHolder onCreateViewHolder( ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_time, viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder( ViewHolder viewHolder, int i) {


        viewHolder.text_view.setText(listEntities.get(i).getTime());

        if (current == i) {
            viewHolder.text_linear.setBackgroundResource(R.drawable.shape_yello_circular);
        } else {
            viewHolder.text_linear.setBackgroundResource(R.drawable.shap_gray_semicircle);
        }

        viewHolder.text_linear.setOnClickListener(e -> {
            onclick.onclick(i);
            current = i;
            notifyDataSetChanged();
        });


    }

    @Override
    public int getItemCount() {
        return listEntities.size();
    }

    public interface Onclick {

        void onclick(int c);

    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.text_view)
        TextView text_view;


        @BindView(R.id.text_linear)
        LinearLayout text_linear;
        public ViewHolder( View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
